
#include "TcpServer.hpp"
#include "Http.hpp"


HttpResponse Login(HttpRequest& req)
{
    HttpResponse resp;
    std::cout << "外部参数已到手：" << std::endl; 
    req.GetResultBody();
    std::cout << "#################################" << std::endl;
    resp.AddCode(200, "OK");
    resp.AddBodyText("<html><h1>Result Done!</h1></html>");
    return resp;
}


int main(int argc, char* argv[])
{
    if (argc != 2)
    {
        std::cout << "Usage: " << argv[0] << " Local-Port" << std::endl;
        exit(0);
    }
    in_port_t port = std::stoi(argv[1]);

    HttpServer http_server;

    http_server.InsertService("/login", Login);

    std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(
        std::bind(&HttpServer::HandlerHttpRequest, &http_server, std::placeholders::_1), 
        port);
    tsvr->Loop();

    return 0;
}

